//
//  SNormalLayout.m
//  CollectionViewDemo
//
//  Created by Samuel on 4/13/15.
//  Copyright (c) 2015 Samuel. All rights reserved.
//

#import "SNormalLayout.h"

@implementation SNormalLayout
#define ITEM_SIZE_WIGTH 80
#define ITEM_SIZE_HIGHT 105
#define ACTIVE_DISTANCE 200
#define ZOOM_FACTOR 0.3
-(id)init
{
    self = [super init];
    if (self) {
        /**
         *  每一个item的大小
         *
         *  @param 长
         *  @param 宽
         *
         *  @return
         */
        self.itemSize = CGSizeMake(ITEM_SIZE_WIGTH, ITEM_SIZE_HIGHT);
        /**
         *  控制横竖
         */
        self.scrollDirection = UICollectionViewScrollDirectionVertical;
        /**
         *  控制每个section的尺寸（横着的一行）
         *
         *  @param    整个视图 上方－离边框的距离
         *  @param    左边－离边框的距离
         *  @param    整个视图 下方－离边框的距离
         *  @param    右边－离边框的距离
         *
         *  @return nil
         */
        self.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        /**
         *  纵向item最小的间隔(由于向下会自动延伸，所以暂无其他)
         */
        self.minimumLineSpacing = .5;
        /**
         *  横向每个item的最小间隔，可以通过“数量”，“间距”的设置使其变大，但是不能低于最小值，否则会向后挤压
         */
        self.minimumInteritemSpacing = 0;
    }
    return self;
}

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)oldBounds
{
    return YES;
}

//-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect
//{
//    NSArray* array = [super layoutAttributesForElementsInRect:rect];
//        CGRect visibleRect;
//        visibleRect.origin = self.collectionView.contentOffset;
//        visibleRect.size = self.collectionView.bounds.size;
//    
//        for (UICollectionViewLayoutAttributes* attributes in array) {
//            if (CGRectIntersectsRect(attributes.frame, rect)) {
//                CGFloat distance = CGRectGetMidX(visibleRect) - attributes.center.x;
//                CGFloat normalizedDistance = distance / ACTIVE_DISTANCE;
//                if (ABS(distance) < ACTIVE_DISTANCE) {
//                    CGFloat zoom = 1 + ZOOM_FACTOR*(1 - ABS(normalizedDistance));
//                    attributes.transform3D = CATransform3DMakeScale(zoom, zoom, 1.0);
//                    attributes.zIndex = 1;
//                }
//            }
//        }
//    return array;
//}
////
//
//- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity
//{
//    CGFloat offsetAdjustment = MAXFLOAT;
//    CGFloat horizontalCenter = proposedContentOffset.x + (CGRectGetWidth(self.collectionView.bounds) / 2.0);
//
//    CGRect targetRect = CGRectMake(proposedContentOffset.x, 0.0, self.collectionView.bounds.size.width, self.collectionView.bounds.size.height);
//    NSArray* array = [super layoutAttributesForElementsInRect:targetRect];
//
//    for (UICollectionViewLayoutAttributes* layoutAttributes in array) {
//        CGFloat itemHorizontalCenter = layoutAttributes.center.x;
//        if (ABS(itemHorizontalCenter - horizontalCenter) < ABS(offsetAdjustment)) {
//            offsetAdjustment = itemHorizontalCenter - horizontalCenter;
//        }
//    }
//    return CGPointMake(100 , 100);
//
//    return CGPointMake(proposedContentOffset.x + offsetAdjustment, proposedContentOffset.y);
//}


@end
